import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_entity.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/list_widget.dart';
import 'package:xiongan_app_yy/widgets/search_widget.dart';

class InvSearchPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return InvSearchPageState();
  }
}

class InvSearchPageState extends State<InvSearchPage>{
  int size=0;
  InvListEntity invListEntity;
  @override
  Widget build(BuildContext context) {
    return SearchWidget(tipsText: "请输入发货通知单号或司机姓名",onTapFuns: (value){
      if(value!=null&&value.toString().length>0){
        onSearch(value);
      }else{
        TostUtil.showToast("请输入发货通知单号或司机姓名");
      }

    },child: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          InvListData data = invListEntity.datas.elementAt(index);
          return ListWidget(
            context: context,
            index: index,
            data: data,
            type: "入库预约单",
          );
        },
        separatorBuilder: (BuildContext context, int index) =>
            Divider(height: 1, color: Colors.transparent),
        itemCount: size),);
  }

  void onSearch(String str) {
    InternetAPI.getInstance()
        .get("OMS/MiWarehouseInTask/GetAllMiWarehouseInTask", (data) {
      setState(() {
        invListEntity = InvListEntity.fromJson(data);
        size = invListEntity.datas.length;
      });
    }, params: {
      'operaterUserId': DataSingleton().Data.id,
      'tenantId': DataSingleton().Data.tenantId,
      "appointmentmode":"20",
      "SearchContent":str
    });
  }

}